package ModelLayer;
import java.util.ArrayList;


/**
 * a Container for the class Costumer. 
 * 
 * @author Team Black 
 * @version 1.0
 */
public class CustomerLibrary
{
    private ArrayList<Customer> customerList;
    private static CustomerLibrary Instance;

    /**
     * Constructor for objects of class CustomerLibrary
     */
    private CustomerLibrary()
    {
        customerList = new ArrayList<Customer>();
    }
    
    /**
     * makes the container singleton
     */
    public static CustomerLibrary getInstance()
    {
        if(Instance == null)
        {
            Instance = new CustomerLibrary();
        }
       return Instance;
    }
    /**
     * adds a costumer to the container
     */    
    public void addCustomer(Customer _customer)
    {
        customerList.add(_customer);
    }
    /**
     * removes a Costumer from the list of costumers
     */
    public void removeCustomer(Customer _customer)
    {
        customerList.remove(_customer);
    }
    /**
     * searh for a costumer, by the Name
     */
    public Customer searchByName(String _name)
    {
        Customer retcustomer = null;
        int index = 0;
        boolean found =false;
        
        while(index < customerList.size() && !found)
        {
            Customer currcustomer = customerList.get(index);
            if(currcustomer.getName().equalsIgnoreCase(_name))
            {
                retcustomer = currcustomer;
                found = true;
            }
            else
            {
                index++;
            }
        }
        return retcustomer;
    }
    /**
     * search for a costumer, by the id
     */
    public Customer searchById(int _id)
    {
        Customer retcustomer = null;
        int index = 0;
        boolean found =false;
        
        while(index < customerList.size() && !found)
        {
            Customer currcustomer = customerList.get(index);
            if(currcustomer.getId() == _id)
            {
                retcustomer = currcustomer;
                found = true;
            }
            else
            {
                index++;
            }
        }
        return retcustomer;
    }
    /**
     * returns a list of costumers, that are currently in the container.
     */
    public ArrayList<Customer> returnAllCustomers()
    {
        return customerList;
    }

}
